<!--
/*******************************************************************************
#      ____               __          __  _      _____ _       _               #
#     / __ \              \ \        / / | |    / ____| |     | |              #
#    | |  | |_ __   ___ _ __ \  /\  / /__| |__ | |  __| | ___ | |__   ___      #
#    | |  | | '_ \ / _ \ '_ \ \/  \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \     #
#    | |__| | |_) |  __/ | | \  /\  /  __/ |_) | |__| | | (_) | |_) |  __/     #
#     \____/| .__/ \___|_| |_|\/  \/ \___|_.__/ \_____|_|\___/|_.__/ \___|     #
#           | |                                                                #
#           |_|                 _____ _____  _  __                             #
#                              / ____|  __ \| |/ /                             #
#                             | (___ | |  | | ' /                              #
#                              \___ \| |  | |  <                               #
#                              ____) | |__| | . \                              #
#                             |_____/|_____/|_|\_\                             #
#                                                                              #
#                              (c) 2010-2011 by                                #
#           University of Applied Sciences Northwestern Switzerland            #
#                     Institute of Geomatics Engineering                       #
#                           martin.christen@fhnw.ch                            #
********************************************************************************
*     Licensed under MIT License. Read the file LICENSE for more information   *
*******************************************************************************/

                      TUTORIAL 9: Using PointSprites
                      
*******************************************************************************/
-->
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="../../../external/closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../../../compiled/deps.js"></script>
<script type="text/javascript">goog.require('owg.OpenWebGlobe');</script>

<script type="text/javascript">

//------------------------------------------------------------------------------
// Render-Event: called every frame:
function OnRender(context)
{
   ogSetTextColor(context,1,1,1);
  //ogDrawText(context, "Press 1 to move to a given position", 0, 130);
   ogSetTextColor(context,1,0,0);
}



//------------------------------------------------------------------------------
function OnKeyDown(ctx,key)
{
   var scene = ogGetScene(ctx);

   if(key == 49) // 1 - Fly to pointcloud
   {
      ogFlyTo(scene,7.6374,47.5335,1285.8677); //scene,longitude,latitude,elevation
   }
   
   if(key == 50) // 2 - hide pointcloud
   {
      ogHideGeometry(geometry1);
      ogHideGeometry(geometry2);
      ogHideGeometry(geometry3);
   }
   
   if(key == 51) // 3 - show pointcloud
   {
      ogShowGeometry(geometry1);
      ogShowGeometry(geometry2);
      ogShowGeometry(geometry3);
   }
   if(key == 52) // 3 - destroy part of pointcloud
   {
      ogDestroyGeometry(geometry1);
   }
   

}

//------------------------------------------------------------------------------
function main()
{
   // (0) Set location of Artwork directory. Because of CORS this can't be local
   // if you want to open this using file://...
   ogSetArtworkDirectory("http://www.openwebglobe.org/art/");
   
   // (1) create an OpenWebGlobe context using canvas
   // first parameter is canvas-id and second is "fullscreen"
   var ctx = ogCreateContextFromCanvas("canvas", true);
   
   // (2) Create a virtual globe
   var globe = ogCreateGlobe(ctx);
   
   // (3) Add an image and an elevation layer
   
   var imgBlueMarble500 = 
   {
      url     : ["http://www.openwebglobe.org/data/img"],
      layer   : "World500",
      service : "i3d"
   };
   
   var elvSRTM_CH = 
   {
      url     : ["http://www.openwebglobe.org/data/elv"],
      layer   : "SRTM",
      service : "i3d"
   };
   
   //ogAddImageLayer(globe, imgBlueMarble500);
   //ogAddElevationLayer(globe, elvSRTM_CH);
   
var imgSWISSTOPO = 
   {
      url     : ["http://10.42.2.37/"],
      layer   : "swissimage", 
      service : "owg"
   };
	
	var elvDHM =
	{
		url     : ["http://10.42.2.37/"],
      layer   : "DHM25",
      service : "owg"
	}

   
	ogAddImageLayer(globe, imgSWISSTOPO);
   ogAddElevationLayer(globe, elvDHM);
   
   
   // (4) Set the "Render-Callback" function.
   // The callback function will be called everytime a frame is drawn.
   ogSetRenderFunction(ctx, OnRender);
   
   
   // (5) Set the mouse down function. We need this for picking!
   ogSetKeyDownFunction(ctx, OnKeyDown);
   
   
   // (6) Set the background color
   ogSetBackgroundColor(ctx, 0.2,0.2,0.7,1);
   
   // (7) get the scene and the world
   var scene = ogGetScene(ctx);   
   var world = ogGetWorld(scene);
 
                  
   geometrylayer = ogCreateGeometryLayer(world,"ps");
      
   // if no indexbuffer -> then it's a pointsprite !
   //geometry = ogCreateGeometry(geometrylayer, points);
   
   var pcoptions = { "id"               :  "1",
                     "Center"           :  [7.637986,47.533279,281.261592],
                     "VertexSemantic"   :  "pc",
                     "PointUrl"         :  "points.xyz",
                     "NumberOfPoints"   :  70000000,
                     "Type" : "pointcloud"
   }
   
   geometry1 = ogCreateGeometry(geometrylayer,pcoptions);
 
   

   //geometry2 = ogLoadGeometryAsync(geometrylayer,"mypointcloud.json");

  
   var cam = ogGetActiveCamera(scene);
   ogSetPosition(cam,7.636721,47.53327,290);

   
}
//------------------------------------------------------------------------------
</script>
</head>
<body onload="main()" style="padding:0px; margin:0px; overflow:hidden;">
   <canvas id="canvas"></canvas>          
</body>
</html>
